﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScannerClasses
{
    public class Token : IToken
    {
        private TokenTypes.TokenType _type;
        private string _spelling;

        public TokenTypes.TokenType Type
        {
            get
            {
                return _type;
            }
            set
            {
                _type = value;
            }
        }
        public string Spelling
        {
            get
            {
                return _spelling;
            }
            set
            {
                _spelling = value;
            }
        }

        public Token(TokenTypes.TokenType type, string spelling)
        {
            _type = type;
            _spelling = spelling;
            if (_type == TokenTypes.TokenType.IDENTIFIER)
            {
                try
                {
                    _type = TokenTypes.keywords.Where(x => x.Value == _spelling).First().Key;
                }
                catch (Exception)
                {
                }
            }
        }

        public override string ToString()
        {
            return string.Format("Token: Spelling - {0} \t, Type - {1}\t", _spelling, _type);
        }
    }
}
